package dbm

import (
	"fmt"
	"gopkg.in/mgo.v2"
)

type MgoBase struct {
	Session  *mgo.Session
	Host     string
	Port     string
	Database string
}

func NewMgoBase(host string, port string, database string) (*MgoBase, error) {
	fmt.Println("NewMgoBase", host, port, database)

	obj := &MgoBase{}

	obj.Host = host
	obj.Port = port
	obj.Database = database
	session, err := mgo.Dial("mongodb://" + host + ":" + port)
	if err == nil {
		obj.Session = session
		obj.Session.SetMode(mgo.Monotonic, true)
		obj.Session.SetPoolLimit(300)
	}
	return obj, err
}
func (db *MgoBase) New() *MgoSession {
	return &MgoSession{Session: db.Session.Clone(), Database: db.Database}
}
